#ifndef _USER_LED_WS2812_DRIVE_H_
#define _USER_LED_WS2812_DRIVE_H_

#include "platform_api.h"
#include "profile.h"

#define WS2812_SPI_DRV_PORT      AHB_SSP0


#define SPI_DMA_TX_CHANNEL   (0)//DMA channel 0


#define WS2812B_DO        GIO_GPIO_28

//#define WS2812B_DO        GIO_GPIO_11
#define log_printf    platform_printf


#define RGB_LED_MAX_NUM  			(4u)

#define SPI_SPEED_4M			6
#define SPI_SPEED_8M			2
#define SPI_SPEED_16M			1

#define LED_WS2812_SPI_SPEED	SPI_SPEED_4M

#if (LED_WS2812_SPI_SPEED == SPI_SPEED_4M)

#define LED_WS2812_HIGH	0X0E
#define LED_WS2812_LOW	0X08

#define DMA_TRANS_SIZE		((RGB_LED_MAX_NUM) * (12))

#elif (LED_WS2812_SPI_SPEED == SPI_SPEED_8M)

#define LED_WS2812_BIT_0	0X0003

#define LED_WS2812_BIT_1	0X007F

#define DMA_TRANS_SIZE		((RGB_LED_MAX_NUM) * (48))
#else
#define LED_WS2812_0_HIGH	0X00000003
#define LED_WS2812_0_LOW	0XFFFFFFFC

#define LED_WS2812_1_HIGH	0X00000003
#define LED_WS2812_1_LOW	0XC0
#define DMA_TRANS_SIZE		((RGB_LED_MAX_NUM) * (96))
#endif

#define TRANS_DATA_NUM		((DMA_TRANS_SIZE) >> (2))

#define TRANS_DATA_NUM		((DMA_TRANS_SIZE) >> (2))

#define SPI_TRANS_CTRL_VALUE    (*(uint32_t *)0x40160020)
#define SPI_SET_WRITE_CNT(c)    SPI_TRANS_CTRL_VALUE = ((SPI_TRANS_CTRL_VALUE & (~(0x1ff << 12))) | ((c - 1) << 12))

void led_mode_show(uint32_t color);
void LED_Task_Init(void);
void bsp_led_on_off(uint8_t on_off);
uint8_t LED_Init(void);
void LED_uninit(void);

#endif